package com.example.service.impl;

import com.example.mapper.DataSumMapper;
import com.example.mapper.LoginMapper;
import com.example.pojo.Login;
import com.example.service.DataSumService;
import com.example.service.LoginService;
import com.example.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper LoginMapper ;
    @Override
    public Login login1(Login login) {
        Login p = LoginMapper.selectBypassword(login);

        if (p != null) {
            Map<String,Object> claims =new HashMap<>();
            claims.put("id",p.getId());
            claims.put("username",p.getUsername());
            String jwt = JwtUtils.generateJwt(claims);
            return new Login(p.getId(), p.getUsername(), p.getName(), jwt, p.getPassword());
        }
        log.warn("No employee found with username: {} and password: {}", login.getUsername(), login.getPassword());
        return null;
    }



}
